<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.10/dist/vue.js"></script>
</head>

<body>

  <div id="app">
    <!-- @add表示自定义事件 -->
    <!-- $event表示子传递给父的数据 -->
    <!-- 子传递数据给父-->
    <ml-a :couter="couter" @add="couter+=$event"></ml-a>
    <hr>
    <ml-b :couter="couter" @add="couter+=$event"></ml-b>
  </div>

  <script>
    Vue.component("ml-a", {
      template: `
                <div>
                    <div>我是ml-a组件 -- {{couter}}</div>
                    <button @click="$emit('add',1)">+1</button>
                </div>
            `,
      props: {
        couter: { type: Number, default: 0 }
      }
    })
    Vue.component("ml-b", {
      template: `
                <div>
                    <div>我是ml-b组件 -- {{couter}}</div>
                    <button @click="$emit('add',1)">+1</button>
                </div>
            `,
      props: {
        couter: { type: Number, default: 0 }
      }
    })
    let vm = new Vue({
      el: "#app",
      data() {
        return {
          couter: 0
        }
      }
    });
  </script>

</body>

</html>